package com.itheima.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitMq配置类
 *
 * @author zwj
 * @version 1.0
 * @createTime 2024/9/8
 */
//@Configuration
public class FanoutConfig {
    /**
     * 声明FanoutExchange交换机
     *
     * @return FanoutExchange
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return ExchangeBuilder.fanoutExchange("hmall.fanout").build();
    }

    /**
     * 声明队列 fanout.queue1
     *
     * @return Queue
     */
    @Bean
    public Queue fanoutQueue1() {
        return QueueBuilder.durable("fanout.queue1").build();
    }

    /**
     * 绑定交换机hmall.fanout 与 队列fanout.queue1
     * @param fanoutExchange fanout交换机
     * @param fanoutQueue1 队列
     * @return Binding
     */
    @Bean
    public Binding bindingQueue1(FanoutExchange fanoutExchange, Queue fanoutQueue1) {
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    /**
     * 声明队列 fanout.queue2
     *
     * @return Queue
     */
    @Bean
    public Queue fanoutQueue2() {
        return QueueBuilder.durable("fanout.queue2").build();
    }

    /**
     * 绑定交换机hmall.fanout 与 队列fanout.queue2
     * @param fanoutExchange fanout交换机
     * @param fanoutQueue2 队列
     * @return Binding
     */
    @Bean
    public Binding bindingQueue2(FanoutExchange fanoutExchange, Queue fanoutQueue2) {
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }

}
